﻿using Abp.vNext.WT.Domain.Issues;
using Abp.vNext.WT.WebApi.Contracts.Issues;
using Abp.vNext.WT.WebApi.Contracts.Issues.Dtos;
using Volo.Abp.Application.Services;

namespace My.Application.Issues
{
    public class IssueAppService : ApplicationService, IIssueAppService
    {
        private readonly IIssueRepository _issueRepository;
        private readonly IssueManager _issueManager;

        public IssueAppService(IIssueRepository issueRepository,
            IssueManager issueManager)
        {
            _issueRepository = issueRepository;
            _issueManager = issueManager;
        }

        public async Task<bool> CreateIssueAsync(List<IssueDto> issueDtos)
        {
            var issueList = ObjectMapper.Map<List<IssueDto>, List<Issue>>(issueDtos);
            await _issueRepository.InsertManyAsync(issueList);

            return true;
        }

        public async Task<List<IssueDto>> GetListAsync()
        {
            var issues = await _issueRepository.GetListAsync();

            return ObjectMapper.Map<List<Issue>, List<IssueDto>>(issues);
        }

        public async Task<bool> AssignToUserAsync()
        {
            var issues = await _issueRepository.GetListAsync();
            var issue = issues.SingleOrDefault();

            Guid User2Id = Guid.Parse("2DAB4460-C21B-4925-BF41-A52750A9B999");

            _ = _issueManager.AssignToUserAsync(issue, User2Id);

            return true;
        }
        
    }
}
